import {RawLocation} from "vue-router";
import {DeepFlatten} from "@/utils/tshelper";
import {Vue} from "vue/types/vue";
import {Formatter} from "@/config/forms";
import {avatar} from "@/config/properties";

const mixin = {
    methods: {
        hasModifier(defaultClass, modifier, flag) {
            return flag ? `${defaultClass} ${defaultClass}--${modifier}` : defaultClass
        },
        $replaceRoute(this: Vue, route: RawLocation) {
            return this.$router.replace(route);
        },
        $popRoute(this: Vue) {
            this.$router.go(-1);
        },
        $pushRoute(this: Vue, route: RawLocation) {
            return this.$router.push(route);
        },
        windowReload() {
            window.location.reload();
        }, navigateTo(link) {
            location.href = link;
        },
        addrFmt(item){
            return Formatter.addrFmt(item)
        },
        addrFmtCode(item){
            return Formatter.addrFmtCode(item)
        }
    },
    computed: {
        randomPic() {
            return `http://www.qqchuang.com.cn/public/uploads/img/20200723/e3efaf380a9abe7c13035513312238de.jpg`
        },
        placeholderPic() {
            return require("@/assets/img/not-found.png")
        },
        avatar(){
            return avatar;
        }
    }
};
export default function CommonPlugin(Vue) {
    return Vue.mixin(mixin)
}
const mixinData = {...mixin};
type CommonMixinType = DeepFlatten<typeof mixinData>;
export {CommonMixinType}
